package com.wangsd.web.shop.service;

import com.gitee.fastmybatis.core.query.Query;
import com.gitee.fastmybatis.core.query.Sort;
import com.wangsd.common.utils.DateUtils;
import com.wangsd.web.shop.entity.MemberIntegral;
import com.wangsd.web.shop.entity.MemberQiandao;
import com.wangsd.web.shop.mapper.MemberIntegralMapper;
import com.wangsd.web.shop.mapper.MemberQiandaoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class MemberQiandaoService {
    @Resource
    MemberQiandaoMapper mapper;

    public void save(String miniOpenid) {
        MemberQiandao qiandao = new MemberQiandao();
        qiandao.setMiniOpenid(miniOpenid);
        qiandao.setQiandaoTime(DateUtils.formatDate(new Date()));
        mapper.saveIgnoreNull(qiandao);
    }

    /**
     * 判断当天是否已签到
     * @param miniOpenid
     * @return
     */
    public boolean checkDate(String miniOpenid) {
        Query query = new Query();
        query.eq("mini_openid", miniOpenid);
        query.eq("qiandao_time", DateUtils.formatDate(new Date()));
        MemberQiandao qiandao = mapper.getByQuery(query);
        if (qiandao == null) {
            return true;
        }else {
            return false;
        }
    }
}
